package com.nuaa.ange.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;

/**
 * @description swagger config
 * @author 玦离
 * @date 2022/12/28 23:25
 */

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 配置了Swagger的Docket的bean实例
     */
    @Bean
    public Docket docket()
    {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("")
                // 是否启用swagger，如果为false，则不能在浏览器中访问
                .enable(true)
                .select()
                // RequestHandlerSelectors配置要扫描接口的方式
                // basePackage指定要扫描的包
                // any扫描全部，none都不扫描
                // withClassAnnotation扫描类上的注解，参数是一个注解的反射对象
                // withMethodAnnotation扫描方法上的注解
                .apis(RequestHandlerSelectors.any())
                // 过滤路径
                // .paths(PathSelectors.ant("/kuang/**"))
                // 创造
                .build();
    }

    /**
     * 配置Swagger信息=apiInfo
     */
    private ApiInfo apiInfo()
    {
        // 作者信息
        Contact contact = new Contact("jueli", "", "");

        return new ApiInfo(
                "暗格文档",
                "暗格的接口描述",
                "1.0",
                "",
                contact,
                "Apache 2.0",
                "https://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>()
        );
    }
}
